package com.tj.tj_java.controller;


import com.tj.tj_java.dto.FavoriteDto;
import com.tj.tj_java.result.Result;
import com.tj.tj_java.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;

    //根据用户 id 搜索 获取全部用户收藏音乐列表 包含模糊查询
    @GetMapping("/getUserFavoriteMusic")
    public Result getUserFavoriteMusic(@RequestParam int userId,@RequestParam String musicTitle){
        System.out.println("首页歌曲列表->"+userId+musicTitle);
        return favoriteService.getUserFavoriteMusicList(userId,musicTitle);
    }

    //收藏
    @PostMapping("/addFavorite")
    public Result addFavorite(@RequestBody FavoriteDto favoriteDto){
        System.out.println("收藏userId->"+favoriteDto.getUserId()+"musicId"+favoriteDto.getMusicId());
        return favoriteService.addFavorite(favoriteDto.getUserId(),favoriteDto.getMusicId());
    }

    //取消收藏
    @PostMapping("/removeFavorite")
    public Result removeFavorite(@RequestBody FavoriteDto favoriteDto){
        System.out.println("取消收藏userId->"+favoriteDto.getUserId()+"musicId"+favoriteDto.getMusicId());
        return favoriteService.removeFavorite(favoriteDto.getUserId(),favoriteDto.getMusicId());
    }


}
